

import 'package:my_flu01/page/pub/CommonBottomBar.dart';
import 'package:shirne_dialog/shirne_dialog.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:card_swiper/card_swiper.dart';

import '../common/card_widget.dart';
import '../utils/tools.dart';
import 'package:go_router/go_router.dart';

class HomePage extends StatefulWidget {
  final String text;
  final Map map;

  const HomePage({Key? key,
    required this.text, // 接收一个text参数
    required this.map //接收一个userBean类
  }) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();

}

class _HomePageState extends State<HomePage> {
  final String _title = "临风hanson HomePage";
  @override
  initState() {
    super.initState();
    //_init();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(_title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          //
          // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
          // action in the IDE, or press "p" in the console), to see the
          // wireframe for each widget.
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '77777',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            Text(
              '33333',
              style: Theme.of(context).textTheme.headlineLarge,
            ),
            SizedBox(height: 10),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Expanded(
                  child: Container(
                    height: 50,
                    margin: EdgeInsets.all(5),
                    child: ElevatedButton(
                      onPressed: (){
                        GoRouter.of(context).push("/listview");
                      },
                      child: Text('viewPage'),
                      style: ButtonStyle(
                          backgroundColor:
                          MaterialStateProperty.all(Colors.black), //背景色
                          foregroundColor:
                          MaterialStateProperty.all(Colors.red) //字体色
                      ),
                    ),

                  ),

                ),
                Expanded(
                  child: Container(
                    height: 50,
                    margin: EdgeInsets.all(5),
                    child: ElevatedButton(
                      onPressed: (){GoRouter.of(context).push("/button");},
                      child: Text('MyButtonPage页面'),
                      style: ButtonStyle(
                          backgroundColor:
                          MaterialStateProperty.all(Colors.black), //背景色
                          foregroundColor:
                          MaterialStateProperty.all(Colors.white) //字体色
                      ),
                    ),

                  ),

                )
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Expanded(
                  child:Container(
                    height: 50,
                    margin: EdgeInsets.all(5),
                    child: ElevatedButton(
                      onPressed: (){
                        GoRouter.of(context).push('/login');
                      },
                      child: Text('我的login页面'),
                      style: ButtonStyle(
                          backgroundColor:
                          MaterialStateProperty.all(Colors.black), //背景色
                          foregroundColor:
                          MaterialStateProperty.all(Colors.white) //字体色
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child:Container(
                    height: 50,
                    margin: EdgeInsets.all(5),
                    child: ElevatedButton(
                      onPressed: (){
                        GoRouter.of(context).push('/foreachView');
                      },
                      child: Text('我的ui-foreach-view'),
                      style: ButtonStyle(
                          backgroundColor:
                          MaterialStateProperty.all(Colors.black), //背景色
                          foregroundColor:
                          MaterialStateProperty.all(Colors.white) //字体色
                      ),
                    ),
                  ),
                ), Expanded(
                  child:Container(
                    height: 50,
                    margin: EdgeInsets.all(5),
                    child: ElevatedButton(
                      onPressed: (){
                        GoRouter.of(context).push('/ListViewBuilderPage');
                      },
                      child: Text('我的ui-foreach-ListViewBuilderPage'),
                      style: ButtonStyle(
                          backgroundColor:
                          MaterialStateProperty.all(Colors.black), //背景色
                          foregroundColor:
                          MaterialStateProperty.all(Colors.white) //字体色
                      ),
                    ),
                  ),
                )

              ],

            ),
            Row( //3
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Expanded(
                  child:Container(
                    height: 50,
                    margin: EdgeInsets.all(5),
                    child: ElevatedButton(
                      onPressed: (){
                        GoRouter.of(context).push('/test');
                      },
                      child: Text('我的test页面'),
                      style: ButtonStyle(
                          backgroundColor:
                          MaterialStateProperty.all(Colors.black12), //背景色
                          foregroundColor:
                          MaterialStateProperty.all(Colors.white) //字体色
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child:Container(
                    height: 50,
                    margin: EdgeInsets.all(5),
                    child: ElevatedButton(
                      onPressed: (){
                        GoRouter.of(context).push('/gridView');
                      },
                      child: Text('我的gridView'),
                      style: ButtonStyle(
                          backgroundColor:
                          MaterialStateProperty.all(Colors.blueGrey), //背景色
                          foregroundColor:
                          MaterialStateProperty.all(Colors.white) //字体色
                      ),
                    ),
                  ),
                ), Expanded(
                  child:Container(
                    height: 50,
                    margin: EdgeInsets.all(5),
                    child: ElevatedButton(
                      onPressed: (){
                        GoRouter.of(context).push('/card');
                      },
                      child: Text('我的ui-card'),
                      style: ButtonStyle(
                          backgroundColor:
                          MaterialStateProperty.all(Colors.grey), //背景色
                          foregroundColor:
                          MaterialStateProperty.all(Colors.white) //字体色
                      ),
                    ),
                  ),
                )
              ],
            ),
          Row( //4
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: makeButten(listData),
          )
          ],
        ),
      ),
      //bottomNavigationBar: CommonBottomBar(), // 使用公用的底部框
      floatingActionButton: FloatingActionButton(
        onPressed: (){},
        tooltip: 'Increment',
        child: const Icon(Icons.ac_unit_sharp),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  List<Widget> makeButten(List listDatas){

    var butts = listDatas.map((e){
      return Expanded(

        child: Container(
          height: 50,
          margin: EdgeInsets.all(5),
          child: ElevatedButton(
            onPressed: () {
              GoRouter.of(context).push(e['path']);
            },
            child: Text(e['title']),
            style: ButtonStyle(
                backgroundColor:
                MaterialStateProperty.all(Colors.amber), //背景色
                foregroundColor:
                MaterialStateProperty.all(Colors.white) //字体色
            ),
          ),
        ),
      );
    });
    return butts.toList();
  }

}


List listData=[{
          "path":"/tableview",
          "title":"tableview - 标题"
          }, {
            "path":"/myui01",
            "title":"myui01 -ＵＩ"
          },{
            "path":"/friendCircle",
            "title":"friendCircle- UI"
          }
          ];